define(['jquery','bDialog/dialog','tips/msgbox'],function ($,dialog) {
    return {
        init:function(){
            //退出
            

        },
		success:function(msg,times,fn){
            ZENG.msgbox.show(msg,4,times);
            if(fn){
                setTimeout(function() {
                    fn();
                }, times);
            }
        },
        error:function(msg,times,fn){
            ZENG.msgbox.show(msg,5,times);
            if(fn){
                setTimeout(function() {
                    fn();
                }, times);
            }
        },
        wait:function(msg){
            if(!msg) msg='请等待...';
            ZENG.msgbox.show(msg,6,10000000);
        },
		hide:function(msg){
            ZENG.msgbox.hide();
        },
        confirm:function(tip,fn){
            dialog({id:'cdl',title:'温馨提示',content:tip,icon:'warning',ok:function(){
                if($.isFunction(fn)) fn();
                return false;
            },cancel:function(){ }});
        }
    };
});

//判断是否为空值
function empty(v){
    switch (typeof v){
        case 'undefined' : return true;
        case 'string' : if(v.length == 0) return true; break;
        case 'boolean' : if(!v) return true; break;
        case 'number' : if(0 === v) return true; break;
        case 'object' :
            if(null === v) return true;
            if(undefined !== v.length && v.length==0) return true;
            for(var k in v){return false;} return true;
            break;
    }
    return false;
}

String.prototype.isEmpty = function(){if (this.replace(/(^\s*)|(\s*$)/g, "").length <= 0) { return true; } else { return false; }};
String.prototype.isEmail = function(){if(this.isEmpty() || (!/^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/.test(this))) { return false; } else { return true;}};
String.prototype.isMobile = function(){if(this.isEmpty() || (!/^(13|14|15|18)[0-9]{9}$/.test(this))) { return false; } else { return true; }};
String.prototype.isTel = function(){if(this.isEmpty() || (!/^((00852\-)|((0[1-9][0-9]{1,2})\-)){0,1}([2-9][0-9]{6,7}){1}(\-[0-9]{1,4}){0,1}$/.test(this))) { return false; } else { return true; }};
String.prototype.isPostcode = function(){if(this.isEmpty() || (!/^[0-9]{6}$/.test(this))) { return false; } else { return true; }};
String.prototype.isImg = function(){
    var strFilter = ".jpeg|.gif|.jpg|.png|.bmp|.pic";
    if(this.indexOf('.')>-1){
        var p = this.lastIndexOf(".");
        var strPostfix = this.substring(p,this.length) + '|';
        strPostfix = strPostfix.toLowerCase();
        if(strFilter.indexOf(strPostfix)>-1){
            return true;
        }
    }
    return false;
};
//获取URL参数
function getParameter(val) {
    var uri = window.location.search;
    var re = new RegExp("" + val + "=([^&?]*)", "ig");
    return ((uri.match(re)) ? (uri.match(re)[0].substr(val.length + 1)) : '');
}

function filterHtml(html) {
    var str = html.replace(/<[^>]+>/g, "");

    return str;
}

function filterSpecialCharacter(str){
    str = str.replace(/#/g, '%23');
    str = str.replace(/&/g, '%26');
    return str;
}

//获取字符串的长度
/**
 * 获取字符串的长度
 * @param str 字符串
 * @param mode 模式，若为空，则一个中文一个长度；否则一个中文占两个长度
 * @returns {*}
 */
function getLength(str,mode) {
    if(empty(str)){
        return 0;
    }else{
        if(empty(mode)){
            return str.length;
        }else{
            return Math.ceil(str.replace(/[^\x00-\xff]/g,"aa").length/2);
        }
        //return str.replace(/^\s+|\s+$/ig,'').replace(/[^\x00-\xff]/ig,'x').length;
    }
}

function urldecode(zipStr){
    var uzipStr="";
    for(var i=0;i<zipStr.length;i++){
        var chr = zipStr.charAt(i);
        if(chr == "+"){
            uzipStr+=" ";
        }else if(chr=="%"){
            var asc = zipStr.substring(i+1,i+3);
            if(parseInt("0x"+asc)>0x7f){
                uzipStr+=decodeURI("%"+asc.toString()+zipStr.substring(i+3,i+9).toString());
                i+=8;
            }else{
                uzipStr+=AsciiToString(parseInt("0x"+asc));
                i+=2;
            }
        }else{
            uzipStr+= chr;
        }
    }

    return uzipStr;
}

function StringToAscii(str){
    return str.charCodeAt(0).toString(16);
}
function AsciiToString(asccode){
    return String.fromCharCode(asccode);
}

function pageBack(){
    var a=window.location.href;
    if(/#top/.test(a)){
        window.history.go(-2);
        window.location.load(window.location.href)
    }else{
        window.history.back();
        window.location.load(window.location.href)
    }
}